{% extends "common/layout.html" %}
{% block content %}
    {#标题#}
    <div class="row">
        <div class="col-sm-12">
            <div class="row">
                <div class="col-sm-12">
                    <h2>招标计划纠偏系统</h2>
                </div>
            </div>
            {#搜索#}
            <div class="row search" style="margin-top: 20px">

                <div class="col-sm-1 ">
                    <label>年度</label>
                    <input class="form-control " name="year" value="2021">
                </div>

                <div class="col-sm-2 ">
                    <label>计划时间</label>
                    <select class="form-control " name="plandate">
                        <option>一月</option>
                        <option>二月</option>
                        <option>三月</option>
                        <option>四月</option>
                        <option>五月</option>
                        <option>六月</option>
                        <option>七月</option>
                        <option>八月</option>
                        <option>九月</option>
                        <option>十月</option>
                        <option>十一月</option>
                        <option>十二月</option>
                    </select>
                </div>

                <div class="col-sm-2 ">
                    <label>城市名称</label>
                    <select class="form-control " name="companytwo">
                        {% if current_user.company== "西北区域公司" %}
                            <option>太原公司</option>
                            <option>大同公司</option>
                            <option>临汾公司</option>
                            <option>长治公司</option>
                            <option>呼和浩特公司</option>
                            <option>包头公司</option>
                            <option>通辽公司</option>
                            <option>乌兰察布公司</option>
                            <option>西安公司</option>
                            <option>宝鸡公司</option>
                            <option>渭南公司</option>
                            <option>乌鲁木齐公司</option>
                            <option>兰州公司</option>
                        {% else %}
                            <option>{{ current_user.company }}</option>
                        {% endif %}
                    </select>
                </div>


                <div class='col-sm-1'>
                    <div class="form-group">
                        <label></label>
                        <button type="submit" class="btn btn-primary btn-block do-search " id="dosearch">
                            搜索
                        </button>

                    </div>


                    <script type="text/javascript">
                        {#搜索#}
                        var dosearch = {
                            init: function () {
                                this.eventBind()
                            },
                            eventBind: function () {
                                $(".do-search").click(function () {
                                    var year = $(".search input[name=year]").val();
                                    var plandate = $(".search select[name=plandate]").val();
                                    var companytwo = $(".search select[name=companytwo]").val();
                                    var urlindex = common_ops.buildUrl("/plan/plansearch?year=") + year + "&plandate=" + plandate + "&companytwo=" + companytwo;
                                    document.location.href = urlindex;

                                });
                            }
                        };
                        $(document).ready(function () {
                            dosearch.init();
                        });
                    </script>
                </div>
                {% if current_user.company == "西北区域公司" %}
                    <div class='col-sm-1'>
                        <div class="form-group">
                            <label></label>
                            <button type="submit" class="btn btn-success btn-block do-export " id="doexport">
                                导出
                            </button>
                        </div>

                        <script type="text/javascript">
                            var exporter = {
                                init: function () {
                                    this.eventBind()
                                },
                                eventBind: function () {
                                    $(".do-export").click(function () {
                                        var year = $(".search input[name=year]").val();
                                        var plandate = $(".search select[name=plandate]").val();
                                        var companytwo = $(".search select[name=companytwo]").val();
                                        var urlindex = common_ops.buildUrl("/plan/export?year=") + year + "&plandate=" + plandate + "&companytwo=" + companytwo;
                                        document.location.href = urlindex;

                                    });
                                }
                            };
                            $(document).ready(function () {
                                exporter.init();
                            });
                        </script>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>


    <div class="row" style="margin-top: 10px">
        <div class="col-sm-12 ">


            {#新建#}
            {% if planindex %}
                <div class="row">

                    {% if current_user.company != "西北区域公司" %}
                        <button type="button" class="btn btn-info" data-toggle="modal"
                                data-target="#exampleModal" style="margin-top: 10px;margin-left: 15px"
                                data-companyone=""
                                data-name="" data-companytwo=""
                                data-project="" data-zbsize=""
                                data-zbyt="" data-zbfw=""
                                data-id="" data-classone=""
                                data-classtwo=""
                                data-plandate=""
                                data-stratdate="" data-planstartdate="" data-title="新建计划外招标"><span
                                class="glyphicon glyphicon-plus" aria-hidden="true"></span>新建计划外招标
                        </button>
                    {% endif %}

                </div>

                {#表格#}

                <row class=" data-table">

                    <table class="table table-bordered table-hover">
                        <tr>
                            {#                        <th class="info">序号</th>#}
                            {% if current_user.company == "西北区域公司" %}
                                <th class="info">类型</th>
                            {% endif %}
                            <th class="info">省公司</th>
                            <th class="info">城市公司</th>
                            <th class="info">项目名称</th>
                            <th class="info">工程名称</th>
                            <th class="info">招标总面积</th>
                            <th class="info">业态</th>
                            <th class="info">范围</th>
                            <th class="info">级别</th>
                            <th class="info">邀请招标</th>
                            <th class="success">申请开始日期</th>
                            <th class="success">计划进场日期</th>
                            <th class="warning">实际开始日期</th>
                            <th class="warning">实际进场日期</th>
                            {% if current_user.company == "西北区域公司" %}
                                <th class="info">完成情况</th>
                            {% endif %}
                            {% if current_user.company != "西北区域公司" %}
                                <th class="info">功能</th>
                            {% endif %}


                        </tr>
                        {% for item in planindex %}

                            <tr>
                                {#<th>{{ item.id }}</th>#}
                                {% if current_user.company == "西北区域公司" %}
                                    {% if item.type == 1 %}
                                        <th class="danger">计划外</th>
                                    {% else %}
                                        <th class="success">计划内</th>
                                    {% endif %}
                                {% endif %}
                                <th>{{ item.companyone }}</th>
                                <th>{{ item.companytwo }}</th>

                                <th>{{ item.project }}</th>
                                <th>{{ item.name }}</th>
                                <th>{{ item.zbsize }}</th>
                                <th>{{ item.zbyt }}</th>
                                <th>{{ item.zbfw }}</th>
                                <th>{{ item.classone }}</th>
                                <th>{{ item.classtwo }}</th>
                                <th>{{ item.plandate | showmonth }}</th>
                                <th>{{ item.planstartdate | showmonth }}</th>


                                {% if item.nowdate %}

                                    <th>{{ item.nowdate | showmonth }}</th>
                                    <th>{{ item.startdate | showmonth }}</th>
                                    {% if current_user.company == "西北区域公司" %}
                                        {% if item.differ > 1 %}
                                            <th class="danger">延迟{{ item.differ }}个月</th>
                                        {% else %}
                                            <th class="success">合格</th>
                                        {% endif %}
                                    {% endif %}


                                {% else %}

                                    <th>----</th>
                                    <th>----</th>
                                    {% if current_user.company == "西北区域公司" %}
                                        <th class="warning">未完成</th>
                                    {% endif %}

                                {% endif %}

                                {% if current_user.company != "西北区域公司" %}
                                    <th>
                                        {% if item.nowdate %}
                                            <p>填报完毕</p>
                                        {% else %}
                                            <button type="button" class="btn btn-primary" data-toggle="modal"
                                                    data-target="#exampleModal" data-companyone="{{ item.companyone }}"
                                                    data-name="{{ item.name }}" data-companytwo="{{ item.companytwo }}"
                                                    data-project="{{ item.project }}" data-zbsize="{{ item.zbsize }}"
                                                    data-zbyt="{{ item.zbyt }}" data-zbfw="{{ item.zbfw }}"
                                                    data-id="{{ item.id }}" data-classone="{{ item.classone }}"
                                                    data-classtwo="{{ item.classtwo }}"
                                                    data-plandate="{{ item.plandate }}"
                                                    data-planstartdate="{{ item.planstartdate }}"
                                                    data-title="{{ item.companytwo }}{{ item.project }}">填报完成时间
                                            </button>

                                        {% endif %}
                                    </th>
                                {% endif %}
                            </tr>

                        {% endfor %}
                    </table>
                </row>
            {% endif %}

        </div>
    </div>


    {#    模态框#}
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">新建计划</h4>
                </div>
                <div class="modal-body">
                    <input type="text" class="invisible" id="uid" name="uid" value="{{ current_user.id }}">
                    <input type="text" class="invisible" id="id" name="id">


                    <div class="form-group" id="gcompanyone">
                        <label class="control-label">省公司:</label>
                        <input type="text" class="form-control" id="companyone" name="companyone">
                    </div>

                    <div class="form-group" id="gcompanytwo">
                        <label for="recipient-name" class="control-label">城市公司:</label>
                        <input type="text" class="form-control" id="companytwo" name="companytwo">
                    </div>

                    <div class="form-group" id="gproject">
                        <label for="recipient-name" class="control-label">项目名称:</label>
                        <input type="text" class="form-control" id="project" name="project">
                    </div>

                    <div class="form-group" id="gname">
                        <label for="recipient-name" class="control-label">招标工程名称:</label>
                        <input type="text" class="form-control" id="name" name="name">
                    </div>

                    <div class="form-group" id="gzbsize">
                        <label for="recipient-name" class="control-label">本次招标总建筑面积(万㎡):</label>
                        <input type="number" class="form-control" id="zbsize" name="zbsize">
                    </div>

                    <div class="form-group" id="gzbfw">
                        <label for="recipient-name" class="control-label">业态:</label>
                        <input type="text" class="form-control" id="zbfw" name="zbfw">
                    </div>

                    <div class="form-group" id="gzbyt">
                        <label for="recipient-name" class="control-label">范围:</label>
                        <input type="text" class="form-control" id="zbyt" name="zbyt">
                    </div>

                    <div class="form-group" id="gclassone">
                        <label for="recipient-name" class="control-label">级别:</label>
                        <select class="form-control " id="classone" name="classone">
                            <option>请选择</option>
                            <option>A</option>
                            <option>B</option>
                            <option>C</option>
                        </select>
                    </div>

                    <div class="form-group" id="gclasstwo">
                        <label for="recipient-name" class="control-label">邀请招标:</label>
                        <select class="form-control " id="classtwo" name="classtwo">
                            <option>请选择</option>
                            <option>议标</option>
                            <option>年标</option>
                        </select>
                    </div>

                    {#                    <div class="form-group" id="gplandate">#}
                    {#                        <label for="recipient-name" class="control-label">计划招标申请开始日期:</label>#}
                    {#                        <input type="text" class="form-control" id="plandate" name="plandate">#}
                    {#                    </div>#}

                    <div class="form-group" id="gplandate">
                        <label for="recipient-name" class="control-label">计划招标申请开始日期:</label>
                        <a class='input-group date' id='datetimepicker1'>
                            <input type='text' class="form-control" id="plandate" name="plandate"/>
                            <span class="input-group-addon">
		                    <span class="glyphicon glyphicon-calendar"></span>
		                </span>
                        </a>
                    </div>


                    <div class="form-group" id="gplanstartdate">
                        <label for="recipient-name" class="control-label">计划进场日期</label>
                        <a class='input-group date' id='datetimepicker2'>
                            <input type='text' class="form-control" id="planstartdate" name="planstartdate"/>
                            <span class="input-group-addon">
		                    <span class="glyphicon glyphicon-calendar"></span>
		                </span>
                        </a>
                    </div>

                    <div class="form-group" id="gnowdate">
                        <label for="recipient-name" class="control-label">实际招标申请开始日期:</label>
                        <a class='input-group date' id='datetimepicker3'>
                            <input type='text' class="form-control" id="nowdate" name="nowdate"/>
                            <span class="input-group-addon">
		                    <span class="glyphicon glyphicon-calendar"></span>
		                </span>
                        </a>
                    </div>

                    <div class="form-group" id="gstartdate">
                        <label for="recipient-name" class="control-label">实际进场日期:</label>
                        <a class='input-group date' id='datetimepicker4'>
                            <input type='text' class="form-control" id="startdate" name="startdate"/>
                            <span class="input-group-addon">
		                    <span class="glyphicon glyphicon-calendar"></span>
		                </span>
                        </a>
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">备注:</label>
                        <textarea type="text" class="form-control" id="bz" name="bz"></textarea>
                    </div>


                    <script type="text/javascript">
                        $('#datetimepicker1').datetimepicker({
                            format: 'YYYY-MM',
                            locale: moment.locale('zh-cn')
                        });

                        $('#datetimepicker2').datetimepicker({
                            format: 'YYYY-MM',
                            locale: moment.locale('zh-cn')
                        });

                        $('#datetimepicker3').datetimepicker({
                            format: 'YYYY-MM',
                            locale: moment.locale('zh-cn')
                        });

                        $('#datetimepicker4').datetimepicker({
                            format: 'YYYY-MM',
                            locale: moment.locale('zh-cn')
                        });

                    </script>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button class="btn btn-primary do-add" type="submit" name="add" id="add">新增计划</button>
                        <button class="btn btn-primary do-updata" type="submit" name="updata" id="updata">提交日期</button>
                    </div>

                </div>

            </div>
        </div>
    </div>

    {#    更新文档#}
    <script>
        $(".do-updata").click(function () {
            var btnaction = $(this);
            var url = window.location.href;
            if (btnaction.hasClass("disable")) {
                common_ops.alert("还没提交上去了，别瞎点")
                return
            }

            var nowdate = $("input[id=nowdate]").val();
            var startdate = $("input[id=startdate]").val();
            var id = $("input[id=id]").val();
            var bz = $("textarea[id=bz]").val();


            $.ajax({
                url: common_ops.buildUrl("/plan/updataplan"),
                type: "POST",
                data: {
                    nowdate: nowdate,
                    startdate: startdate,
                    id: id,
                    bz: bz,
                },
                dataType: 'json',
                success: function (res) {
                    btnaction.removeClass("disabled");
                    var callback = null;
                    if (res.code == 200) {
                        callback = function () {
                        };
                    }
                    common_ops.alert(res.msg, callback);
                    setTimeout(function () {
                        $('#exampleModal').modal('hide');
                        $(".modal-backdrop.fade").hide();
                        window.location.href = url;
                        $("#exampleModal").trigger("click");
                    }, 1000)
                }
            });

        });
    </script>


    <script>
        $(".do-add").click(function () {
            var btnaction = $(this);
            var url = window.location.href;
            if (btnaction.hasClass("disable")) {
                common_ops.alert("还没提交上去了，别瞎点")
                return
            }

            var companyone = $("input[id=companyone]").val();
            var companytwo = $("input[id=companytwo]").val();
            var project = $("input[id=project]").val();
            var name = $("input[id=name]").val();
            var zbsize = $("input[id=zbsize]").val();
            var zbfw = $("input[id=zbfw]").val();
            var zbyt = $("input[id=zbyt]").val();
            var classone = $("select[id=classone]").val();
            var classtwo = $("select[id=classtwo]").val();
            var plandate = $("input[id=plandate]").val();
            var planstartdate = $("input[id=planstartdate]").val();
            var uid = $("input[id=uid]").val();
            var bz = $("textarea[id=bz]").val();


            $.ajax({
                url: common_ops.buildUrl("/plan/addplan"),
                type: "POST",
                data: {
                    companyone: companyone,
                    companytwo: companytwo,
                    project: project,
                    name: name,
                    zbsize: zbsize,
                    zbfw: zbfw,
                    zbyt: zbyt,
                    classone: classone,
                    classtwo: classtwo,
                    plandate: plandate,
                    planstartdate: planstartdate,
                    uid: uid,
                    bz: bz
                },
                dataType: 'json',
                success: function (res) {
                    btnaction.removeClass("disabled");
                    var callback = null;
                    if (res.code == 200) {
                        callback = function () {
                        };
                    }
                    common_ops.alert(res.msg, callback);
                    setTimeout(function () {
                        $('#exampleModal').modal('hide');
                        $(".modal-backdrop.fade").hide();
                        window.location.href = url;
                        $("#exampleModal").trigger("click");
                    }, 1000)


                }
            });

        });
    </script>


    <script>
        {#编辑赋值#}
        $('#exampleModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget); // Button that triggered the modal
            var companyone = button.data('companyone');
            var companytwo = button.data('companytwo');
            var project = button.data('project');
            var name = button.data('name');
            var zbsize = button.data('zbsize');
            var zbfw = button.data('zbfw');
            var zbyt = button.data('zbyt');
            var classone = button.data('classone');
            var classtwo = button.data('classtwo');
            var plandate = button.data('plandate');
            var planstartdate = button.data('planstartdate');
            var id = button.data('id');
            var title = button.data('title');

            var modal = $(this)
            modal.find('.modal-title').text(title);
            document.getElementById("companyone").value = companyone;
            document.getElementById("companytwo").value = companytwo;
            document.getElementById("project").value = project;
            document.getElementById("name").value = name;
            document.getElementById("zbsize").value = zbsize;
            document.getElementById("zbfw").value = zbfw;
            document.getElementById("zbyt").value = zbyt;
            document.getElementById("classone").value = classone;
            document.getElementById("classtwo").value = classtwo;
            document.getElementById("plandate").value = plandate;
            document.getElementById("planstartdate").value = planstartdate;
            document.getElementById("id").value = id;

            {#新建#}
            if (typeof (id.length) == 'undefined') {
                document.getElementById("updata").style.display = "";
                document.getElementById("add").style.display = "none";

                document.getElementById("gcompanyone").style.display = "none";
                document.getElementById("gcompanytwo").style.display = "none";
                document.getElementById("gproject").style.display = "none";
                document.getElementById("gname").style.display = "none";
                document.getElementById("gzbsize").style.display = "none";
                document.getElementById("gzbfw").style.display = "none";
                document.getElementById("gzbyt").style.display = "none";
                document.getElementById("gclassone").style.display = "none";
                document.getElementById("gclasstwo").style.display = "none";
                document.getElementById("gplandate").style.display = "none";
                document.getElementById("gplanstartdate").style.display = "none";

                document.getElementById("gnowdate").style.display = "";
                document.getElementById("gstartdate").style.display = "";

                {#编辑#}
            } else {
                document.getElementById("updata").style.display = "none";
                document.getElementById("add").style.display = "";

                document.getElementById("gcompanyone").style.display = "";
                document.getElementById("gcompanytwo").style.display = "";
                document.getElementById("gproject").style.display = "";
                document.getElementById("gname").style.display = "";
                document.getElementById("gzbsize").style.display = "";
                document.getElementById("gzbfw").style.display = "";
                document.getElementById("gzbyt").style.display = "";
                document.getElementById("gclassone").style.display = "";
                document.getElementById("gclasstwo").style.display = "";
                document.getElementById("gplandate").style.display = "";
                document.getElementById("gplanstartdate").style.display = "";

                document.getElementById("gnowdate").style.display = "none";
                document.getElementById("gstartdate").style.display = "none";
            }


        });
    </script>



{% endblock %}


{% block js %}
    <script src="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
{% endblock %}


